package com.itfitness.stretchcalendarview.widget.calendarview.widget

import android.content.Context
import android.util.AttributeSet
import android.widget.AbsListView
import android.widget.GridView

/**
 *
 * @Description:     java类作用描述 自定义高度自适应GridView
 * @Author:         作者名
 * @CreateDate:     2022/2/14 15:39
 * @UpdateUser:     更新者：
 * @UpdateDate:     2022/2/14 15:39
 * @UpdateRemark:   更新说明：
 */
class WrapGridView : GridView {
    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        val heightSpec = if (layoutParams.height == LayoutParams.WRAP_CONTENT) {
            MeasureSpec.makeMeasureSpec(Int.MAX_VALUE shr 2, MeasureSpec.AT_MOST)
        } else {
            heightMeasureSpec
        }
        // 这几行代码比较重要
        super.onMeasure(widthMeasureSpec, heightSpec)
    }
}